<template>
  <div class="activity-box">
    <div class="nav-list">
      <div class="nav" v-for="(item, index) of navList" :key="index" :class="{active: activeNavCategoryId === item.uuid}" @click="changeNav(item)">{{item.name}}</div>
    </div>
    <div class="list-box">
      <div class="card-item" v-for="(item, index) of list" :key="index" :class="{mr0: !((index+1) % 3)}" @click="onDetail(item)">
        <div class="img-box" :style="{backgroundImage: 'url(' + item.coverUrl + ')'}"></div>
        <div class="card-content">
          <div class="title" :title="item.name">{{item.name}}</div>
          <div class="news">{{item.summary}}</div>
        </div>
        <div class="date-box">
          <div class="icon"></div>
          <div class="date">
            <span v-if="item.beginDate">{{formatDate(item.beginDate)}}</span>
            <span v-else>待定</span>
          </div>
        </div>
        <div class="address-box">
          <div class="icon"></div>
          <div class="address">
            <span v-if="item.location">{{item.location}}</span>
            <span v-else>待定</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { tagsList } from '@/api/api';
import moment from 'moment';
moment.locale('zh-cn');

export default {
  props: {
    list: {
      type: Array,
      default() {
        return []
      }
    }
  },
  data() {
    return {
      activeNavCategoryId: '',
      navList: [
        {
          uuid: '',
          name: '全部活动'
        }
      ],
      activityList: []
    }
  },
  mounted() {
    this.getTagsList();
  },
  methods: {
    // 获取活动标签
    async getTagsList() {
      const params = {
        status: 1,
        type: 'HD'
      }
      const res = await tagsList(params);
      this.navList = this.navList.concat(res.list || []);
    },
    changeNav(item) {
      this.activeNavCategoryId = item.uuid;
      this.$emit('changeNav', item.uuid);
    },
    onDetail(item) {
      if (item.liveUrl) {
        window.open(item.liveUrl, '_blank');
      } else {
        let routerJump = this.$router.resolve({ name: 'ActivityDetail', query: {uuid: item.uuid} });
        window.open(routerJump.href, '_blank');
      }
    },
    // 处理时间
    formatDate(date) {
      return moment(date).format('lll');
    }
  }
}
</script>

<style lang="scss" scoped>
.activity-box {
  width: 1180px;
  margin: 0 auto;
  padding-bottom: 72px;
  .nav-list {
    margin-bottom: 30px;
    .nav {
      display: inline-block;
      padding: 0 20px;
      font-size: 16px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #696969;
      line-height: 24px;
      position: relative;
      cursor: pointer;
      &::after {
        position: absolute;
        top: 2px;
        right: 0;
        content: "";
        width: 1px;
        height: 20px;
        background: #D8D8D8;
      }
      &:nth-child(1) {
        padding-left: 0;
      }
      &:last-child {
        &::after {
          display: none;
        }
      }
      &.active {
        font-size: 24px;
        font-family: PingFangSC-Semibold, PingFang SC;
        font-weight: 600;
        color: #272727;
        line-height: 32px;
        position: relative;
        &::after {
          position: absolute;
          top: 8px;
          right: 0;
          content: "";
          width: 1px;
          height: 20px;
          background: #D8D8D8;
        }
      }
    }
  }
  .list-box {
    width: 1180px;
    overflow: hidden;
    .card-item {
      float: left;
      width: 380px;
      height: 436px;
      margin-right: 20px;
      margin-bottom: 20px;
      background: #fff;
      border-radius: 4px;
      cursor: pointer;
      &.mr0 {
        margin-right: 0;
      }
      .img-box {
        width: 380px;
        height: 214px;
        background-size: cover;
        border-radius: 4px;
      }
      .card-content {
        padding: 20px;
        .title {
          height: 56px;
          font-size: 18px;
          font-weight: 600;
          color: #272727;
          line-height: 28px;
          margin-bottom: 4px;
          max-height: 56px;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
          overflow: hidden;
          word-break: break-all;
        }
        .news {
          height: 66px;
          font-size: 14px;
          font-weight: 400;
          color: #696969;
          line-height: 22px;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 3;
          overflow: hidden;
          word-break: break-all;
        }
      }
      .date-box {
        padding: 0 20px;
        font-size: 12px;
        
        font-weight: 400;
        color: #696969;
        line-height: 18px;
        margin-bottom: 4px;
        .icon {
          width: 12px;
          height: 12px;
          background: url('../../../assets/date.png') no-repeat;
          background-size: cover;
          display: inline-block;
          margin-right: 5px;
        }
        .date {
          display: inline-block;
        }
      }
      .address-box {
        padding: 0 20px;
        font-size: 12px;
        
        font-weight: 400;
        color: #696969;
        line-height: 18px;
        .icon {
          width: 12px;
          height: 12px;
          background: url('../../../assets/address.png') no-repeat;
          background-size: cover;
          display: inline-block;
          margin-right: 5px;
        }
        .address {
          display: inline-block;
        }
      }
    }
  }
}
</style>